home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / UTIL / CFG_HAND.CPP < prev    next >
C/C++ Source or Header  |  1994-05-22  |  2KB  |  89 lines

  1. #include "..\au.hpp"
  2. #include <errno.h>
  3.  
  4. /**************************************************************************/
  5. /* open the configuration file, look through path if necessary */
  6.  
  7. STATUS CFG_HANDLE::open(AU *au, char *fn)
  8. {
  9.     int  pathpos=0, dirpos;
  10.     char *path, aupath[200], directory[80];
  11.     char temp[FILE_SIZE];
  12.  
  13.     strcpy(file_name, fn);
  14.     line_number = 0;
  15.  
  16.     if (handle.open(au, file_name, O_TEXT) == SUCCESS)
  17.         return SUCCESS;
  18.  
  19.     if (strstr(file_name, "\\") != NULL)
  20.         return FAILURE;
  21.  
  22. /* Lets try ripping it from argv[0] */
  23.  
  24.     split_file(au->argv0, directory, temp);
  25.     build_fname(directory, directory, file_name);
  26.     if (handle.open(au, directory, O_TEXT) == SUCCESS)
  27.         return SUCCESS;
  28.  
  29. /* lets try for AUPATH envirnonment variable */
  30.  
  31.     if (getenv("AUPATH")!=NULL)
  32.     {
  33.         strcpy(aupath, getenv("AUPATH"));
  34.         append_backslash(aupath);
  35.         strcat(aupath, file_name);
  36.         if (handle.open(au, aupath, O_TEXT) == SUCCESS)
  37.             return SUCCESS;
  38.      }
  39.  
  40. /* Lets try the path */
  41.  
  42.     path = getenv("PATH");
  43.     if (path == NULL)
  44.         return FAILURE;
  45.  
  46.     while (TRUE)
  47.     {
  48.         if (path[pathpos]=='\0')  /* we have looked through the whole PATH without success */
  49.             return FAILURE;
  50.  
  51.         dirpos=0;
  52.         while (path[pathpos]!=';' && path[pathpos]!='\0')
  53.             directory[dirpos++] = path[pathpos++];
  54.  
  55.         if (path[pathpos] == ';')
  56.             pathpos++;       /* get us over the ; */
  57.  
  58.         directory[dirpos] = '\0';
  59.         append_backslash(directory);
  60.         strcat(directory, file_name);
  61.         if (handle.open(au, directory, O_TEXT) == SUCCESS)
  62.             return SUCCESS;
  63.     }
  64. }
  65.  
  66. int CFG_HANDLE::read_line(AU *au, char *string)
  67. {
  68.     int retCode;
  69.  
  70.     retCode = handle.read_line(au, string);
  71.     if (retCode == 0)
  72.         line_number++;
  73.     return retCode;
  74. }
  75.  
  76. /*****************************************************************************/
  77. void CFG_HANDLE::invalid_option(AU *au, char *option)
  78. {
  79.     au_printf_error(au, "Unknown command \"%s\" in %s at line %d",
  80.                     option, file_name, line_number);
  81.     exit(0);
  82. }
  83. /*****************************************************************************/
  84. void CFG_HANDLE::invalid(AU *au, char *msg)
  85. {
  86.     au_printf_error(au, "%s in %s at line %d", msg, file_name, line_number);
  87.     exit(0);
  88. }
  89.